﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using ProgNetComponents.Collections;
using System.Drawing.Design;
using ProgNetComponents.Interfaces;
using ProgNetComponentsDx.Shortcut.Design;

namespace ProgNetComponentsDx.Shortcut
{
    [TypeConverter(typeof(ShortcutGroupTypeConverter))]
    public class ShortcutGroup : ProgNetComponents.Interfaces.INamedGroup
    {
        internal static Color Color
        {
            get { return Color.MistyRose; }
        }
        private string _Name;
        private ShortcutGroupCollection _Groups;
        private ShortcutCollection _Items = new ShortcutCollection();

        public ShortcutGroup()
            : this("", null, null)
        {

        }

        public ShortcutGroup(string name, ShortcutGroup[] childGroups , Shortcut[] Shortcuts )
        {
            _Groups = new ShortcutGroupCollection();
            if (childGroups != null)
            {
                foreach (ShortcutGroup o in childGroups)
                {
                    _Groups.Add(o);
                }
            }
            if (Shortcuts != null)
            {
                _Items.AddRange(Shortcuts);
            }
            Name = name;
        }

        public ShortcutGroup(string name, ShortcutGroup[] childGroups)
            : this(name, childGroups, null)
        {

        }

        public ShortcutGroup(string name)
            : this(name, null, null)
        {

        }

       public ShortcutGroup(string name, Shortcut[] Shortcuts)
            : this(name, null, Shortcuts)
        {

        }

        public string Name
        {
            get { return _Name; }
            set { _Name = ProgNetComponents.Tools.ConstHelper.GetFriendlyName(value); }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public ShortcutGroupCollection Groups
        {
            get { return _Groups; }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public ShortcutCollection Items
        {
            get { return _Items; }
        }

        #region INamedGroup Members

        System.Collections.IList ProgNetComponents.Interfaces.INamedGroup.Groups
        {
            get { return _Groups; }
        }

        System.Collections.IList ProgNetComponents.Interfaces.INamedGroup.Items
        {
            get { return _Items; }
        }

        bool ProgNetComponents.Interfaces.INamedGroup.HasAnyItems()
        {
            if (_Items.Count > 0)
                return true;
            foreach (INamedGroup g in _Groups)
                if (g.HasAnyItems())
                    return true;
            return false;
        }

        #endregion

        
    }
    [Editor(typeof(Design.ShortcutGroupCollectionEditor), typeof(UITypeEditor))]
    public class ShortcutGroupCollection : BaseNamedCollection<ShortcutGroup>
    {
        
    }
}
